package com.jshop.seckill.web.service.impl;

import com.github.pagehelper.PageHelper;
import com.jshop.seckill.http.HttpResult;
import com.jshop.seckill.http.PageResult;
import com.jshop.seckill.domain.StoreProduct;
import com.jshop.seckill.http.StatusCode;
import com.jshop.seckill.mapper.GoodsMapper;
import com.jshop.seckill.web.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 * @Author yaxiongliu
 **/
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    GoodsMapper goodsMapper;


    //分页查询商品列表
    @Override
    public PageResult queryGoodList(Integer pageNo, Integer pageSize) {
        //使用pageHelper进行分页
        PageHelper.startPage(pageNo,pageSize);
        //查询商品列表
        List<StoreProduct> productList=goodsMapper.queryProductList();
        PageResult result = new PageResult();
        //将查询结果封装到PageResult中返回
        result.setRows(productList);
        return result;
    }
    //查询商品详情
    @Override
    public HttpResult findDetail(String pid) {
        HttpResult result = new HttpResult();
        StoreProduct product = goodsMapper.selectByPrimaryKey(pid);
        result.setData(product);
        result.setCode(StatusCode.OK);
        result.setMsg(StatusCode.OK_MSG);
        return result;
    }
}
